# 作者: 肖老师
# 2024年11月17日15时03分29秒
# xxxrlmk@163.com
def use_queue():
    # 使用deque
    from collections import deque

    queue = deque(["Eric", "John", "Michael"])
    queue.append('luke')  # 入队
    print(queue)
    queue.popleft()
    print(queue)  # 出队


class CircleQueue:
    def __init__(self, max_size):
        self.max_size = max_size
        self.arr = [0] * max_size
        self.front = 0
        self.rear = 0

    def en_queue(self, element):
        # 判断队列是否满了
        if (self.rear + 1) % self.max_size == self.front:
            print('队列满了')
            return False
        self.arr[self.rear] = element  # 放入循环队列
        self.rear = (self.rear + 1) % self.max_size
        return True

    def de_queue(self):
        if self.front == self.rear:
            print('队列为空')
            return False
        element = self.arr[self.front]
        self.front = (self.front + 1) % self.max_size
        return element


if __name__ == '__main__':
    use_queue()
    c = CircleQueue(5)
    c.en_queue(1)
    c.en_queue(2)
    c.en_queue(3)
    c.en_queue(4)
    c.en_queue(5)
    print(c.de_queue())
